<?php
class config extends base{

  function __construct()
  {
    parent::__construct();
    $this->m = load('m/config');
  }

  function index()
  {
    $tot = $this->m->count();
    $psize = 30;
    $param['pagination'] = pagination($tot , seg(3) , $psize ,'/config/index/');
    $param['records'] = $this->m->get("", seg(3), $psize);
    $this->display('config/list-table',$param);
  }


  function view($id)
  {
    $param['r'] = $this->m->get($id);
    $this->display('config/show',$param);
  }


  function add()
  {
    $conf = array('name'=>'required','able'=>'required','value'=>'required',);
    
    $err = validate($conf);
    if ( $err === TRUE) {
      $this->m->add();
      redirect('/config/add/','发布成功！');
    }
    else {
      $param['val'] = $_POST; 
      $param['err'] = $err;
      $this->display('config/add',$param);    
    }
  }    

  function edit($id)
  {
    $conf = array('name'=>'required','able'=>'required','value'=>'required',);
    $err = validate($conf);
  	if ( $err === TRUE) {
      $this->m->update($id);
      redirect('/config/','修改成功！');
    }
    else {
      $param['val'] = array_merge($_POST,$this->m->get($id));
      $param['err'] = $err;
      $this->display('config/add',$param);    
    }
  }

  function del($id)
  {
    $this->m->del($id);
    redirect('/config/','删除成功！');
  }
}